/**
 *
 * 建造工具icon
 * @author 
 * 
 */
class BuildIcon extends egret.Sprite{
    
    /**类名*/
    public className: string;
    /**价格*/
    public price: number;
    /**玩家拥有金钱*/
    private gold: number;
    
    public is: boolean;
    
    private xunhuan: egret.Bitmap;
    private confirm: egret.Bitmap;
    private icon: egret.Bitmap;
    private bm: egret.Bitmap;
    private txt: egret.BitmapText;
    private res :any;
    
    private label: string;
    private info: string;
    private type: string;
    private tip: string;
    private life:number;
    private damage:number;
    
	public constructor(towerName:string,gold:number,obj:any) {
        super();
        this.gold = gold;
        this.className = towerName;//获取类名
        if(this.className == "gold") {
            this.price = TowerLevel.soldierData[towerName].price+GuankaBase.instance.goldUp*10;
        } else if(this.className == "tower") {
            this.price = TowerLevel.soldierData[towerName].price + GuankaBase.instance.lifeUp * 10;
        } else if(this.className == "arrow") {
            this.price = TowerLevel.soldierData[towerName].price + GuankaBase.instance.damagekUp * 10;
        } else{
            this.price = TowerLevel.soldierData[towerName].price;//获取价格
        }
        this.res = TowerLevel.soldierData[towerName].res;//获取资源名
        this.is = false;
        this.label = TowerLevel.soldierData[towerName].label;
        this.info = TowerLevel.soldierData[towerName].info;
        this.type = TowerLevel.soldierData[towerName].unitTip;
        this.tip = TowerLevel.soldierData[towerName].tip;
        this.life = TowerLevel.soldierData[towerName].life;
        this.damage = TowerLevel.soldierData[towerName].damage;
        
        //icon
        this.icon = Utils.createBitmapByName(this.res);
        this.addChild(this.icon);
        this.touchEnabled = true;
        if(towerName == "LockTower" ){
            this.touchEnabled = false;
        } else if(towerName == "SellTower"){
            this.is = true;
        }else{
            this.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchHandle,this);

        }

        if(this.price < 4)
            return;
        
        //textbg
        this.bm = Utils.createBitmapByName("cashbg");
        this.bm.x = 8;
        this.bm.y = 32;
        this.addChild(this.bm);
        //text
        this.txt = new egret.BitmapText();
        
        var bf:egret.BitmapFont
        if(this.gold>=this.price)
            bf = RES.getRes("NumFont");
        else
            bf = RES.getRes("NumFont2");
        
        this.txt.font = bf;
        this.txt.letterSpacing = -1;
        this.txt.text = this.price.toString();
        this.txt.x = (30 - this.txt.width) / 2 + 8;
        this.txt.y = 32;
        this.addChild(this.txt);
	}
	
    /**点击事件*/
    protected touchHandle(e: egret.TouchEvent) {
        Group.selectIcon(this);
    }
    /**对象管理事件  选中 重选 取消*/
    public selectIcon() {
        this.icon.texture = RES.getRes("queren"); 
        var board = GuankaBase.instance.guankaUI.boardSp;
        board.visible = true;
        //GuankaBase.instance.removeChild(board);
        GuankaBase.instance.guankaUI.label.text = this.label;
        GuankaBase.instance.guankaUI.type.text = this.type;
        GuankaBase.instance.guankaUI.info.text = this.info;
        GuankaBase.instance.guankaUI.tip.text = this.tip;
        if(this.life != null){
            GuankaBase.instance.guankaUI.lifetxt.text = (Math.floor(this.life * (1 + 0.2 * GuankaBase.instance.lifeUp))).toString();
            GuankaBase.instance.guankaUI.damagetxt.text = (Math.floor(this.damage * (1 + 0.2 * GuankaBase.instance.damagekUp))).toString();
        }else{
            GuankaBase.instance.guankaUI.lifetxt.text = "";
            GuankaBase.instance.guankaUI.damagetxt.text = "";
            
        }
        board.x = this.parent.x-90;
        board.y = this.parent.y - 190;
        
    }
	
    public reselectIcon() {
        
    }
    
    public deselectIcon() {
        this.icon.texture = RES.getRes(this.res);
        this.is = false;
    }
}
